using Machine.Specifications;
using Unbound.Tests.Unbinding.Configuration;
using Unbound.Tests.Unbinding.TestObjects;

namespace Unbound.Tests.Unbinding.Specifications.ComplexTypes
{
	[Subject("Unbinding")]
	public class more_complex_types : unbinding<MoreComplexType>
	{
		protected static MoreComplexType _type =
			new MoreComplexType
				{
					Number = 42,
					Text = "Bar",
					Barf = new MoreComplexType.Bar
					       	{
					       		Digit = 12
					       	}
				};

		Establish context = () =>
		                    	{
		                    		Prefix = "foo";
		                    		Request = _type;
		                    	};

		Behaves_like<behavior> unbinding_worked;

		[Behaviors]
		public class behavior : behavior<MoreComplexType>
		{
			It should_bind_deeply_nested_values = () => ((MoreComplexType) Bound).Barf.Digit.ShouldEqual(12);

			It should_bind_to_type = () => Bound.ShouldBeOfType<MoreComplexType>();

			It should_bind_values = () =>
			                        	{
			                        		((MoreComplexType) Bound).Number.ShouldEqual(42);
			                        		((MoreComplexType) Bound).Text.ShouldEqual("Bar");
			                        	};
		}
	}

	[Subject("Unbinding")]
	public class more_complex_types_sans_prefix : more_complex_types
	{
		Establish context = () =>
		{
			Unbind = () => Request.ToHttpDictionary();
			Prefix = "";
			Request = _type;
		};

		Behaves_like<behavior> unbinding_worked;

	}
}